import axios,{type AxiosResponse} from 'axios'
import { ElMessage,ElMessageBox } from 'element-plus'
//定义response对象接口
interface ResponseData<T>{
    code:number,
    data:T,
    message:string;
}
//配置axios实例
const service = axios.create({
    baseURL:'/mock',
    timeout:3000,

});
//添加请求拦截器
service.interceptors.request.use((config)=>{
    return config;
})
//添加响应拦截器
service.interceptors.response.use(
    //约束response
    async (response: AxiosResponse<ResponseData<any>>)=>{
        //对响应数据
        const res = response.data;
        return res.data
    },
    (error)=>{
        //响应错误
        ElMessage.error('网络超时');
        return Promise.reject(error)
    }
)
export default service;